<template>
  <div style="display: flex;line-height: 60px">
    <div>
      <i :class="icon" style="font-size: 15px;" @click="collapse"></i>
    </div>
    <div style="flex: 1;text-align: center;font-size: 30px;color:#FFFFFF">
      <span>Tutor System</span>
    </div>
    <el-dropdown>
      <i class="el-icon-arrow-down" style="margin-left: 5px;color:#FFFFFF"></i>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item  @click.native="toUser">Personal Center</el-dropdown-item>
        <!-- <el-dropdown-item @click.native="toUser" >Personal Center</el-dropdown-item> -->
        <el-dropdown-item @click.native="logout">logout</el-dropdown-item>
      </el-dropdown-menu>
      <span>{{user.name}}</span>
    </el-dropdown>

  </div>
</template>

<script>
import Router from "../router";

export default {
  name: "Header",
  data(){
    return{
      user:JSON.parse(sessionStorage.getItem('CurUser'))
    }
  },
  props:{
    icon:String
  },
  methods:{
    toUser(){
      console.log('touser')
      this.$router.push("/Home")
    },
    logout(){
      console.log('tas')
      this.$confirm('Are you sure you want to log out？', {
        confirmButtonText: 'confirm',
        type: 'warning',
        center: true, //
      })
        .then(() => {
          this.$message({
            type:'success',
            message:'Successfully exited'
          })

          this.$router.push("/")
          sessionStorage.clear()
        })
        .catch(() => {
          this.$message({
            type:'info',
            message:'Logout cancelled'
          })
        })
    },
    collapse(){
      this.$emit('doCollapse')
    }
  }
}
</script>

<style scoped>

</style>
